package interfaces.superWidgets;

import org.fenggui.binding.render.ImageFont;

public class KeyValueContent extends StaticContent {
		
	protected ImageFont font;
	protected int currentY, lineHeight;
	protected boolean startTop;
	
	public KeyValueContent(int width, int height, ImageFont font, boolean startTop) {
		super(width, height);
		this.font = font;
		this.startTop = startTop;
		
		lineHeight = font.getHeight() / 3 * 4;
		
		initCurrentY();
	}
	
	public void addLine(String key, String value) {
		addLabel(key, false);
		addLabel(value, true);
		
		incrementY();
	}
	
	protected void incrementY() {
		currentY += startTop ? -lineHeight : lineHeight;
	}
	
	protected InterfaceLabel addLabel(String text, boolean right) {
		InterfaceLabel label = new InterfaceLabel(text, font);
		label.setHeight(lineHeight);
		label.setXY(right ? getWidth() - label.getWidth() : 0, currentY);
		addWidget(label);
		return label;
	}
	
	protected void initCurrentY() {
		currentY = startTop ? height - lineHeight : 0;
	}
	
	public void clear() {
		removeAllWidgets();
		initCurrentY();
	}
}